//
//  CJExten+URL.swift
//  CJPack
//
//  Created by 陈警卫 on 2023-09-28.
//

import UIKit
import Foundation

public extension URL {
    
    ///  获取连接中的参数返回字典
    var cj_params: [String: String]? {
        guard let components = URLComponents(url: self, resolvingAgainstBaseURL: true),
              let queryItems = components.queryItems
        else { return nil }
        var params = [String: String]()
        for item in queryItems {
            params[item.name] = item.value
        }
        return params
    }
    
    /// 验证Url
    var cj_canOpen: Bool {
        return UIApplication.shared.canOpenURL(self)
    }
    
}

public extension NSURL {
    
    var url: URL {
        return self as URL
    }
}

public extension NSURL {
    
    ///  获取连接中的参数返回字典
    var cj_params: [String: String]? {
        return url.cj_params
    }
    
    /// 验证Url
    var cj_canOpen: Bool {
        return url.cj_canOpen
    }
    
}


